//
//  BatteryView.m
//  LINNER
//
//  Created by Kendama on 2017/10/11.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "BatteryView.h"
#import "TBCycleView.h"

@interface BatteryView()

@property (strong, nonatomic) UIImageView *cycleBgImageView;
@property (strong, nonatomic) TBCycleView *cycleView;
@property (strong, nonatomic) UILabel *batteryLabel;
@property (strong, nonatomic) UILabel *battery;
@property (strong, nonatomic) UILabel *tipsLabel;
@property (strong, nonatomic) UILabel *tipsTitleLabel;

@end

@implementation BatteryView

#pragma mark -- 事件处理
- (void)setBatteryValue:(CGFloat)value
{
    [self.cycleView drawProgress:value];
    self.batteryLabel.text = [NSString stringWithFormat:@"%.0f%%",value*100];
}


#pragma mark -- 懒加载
- (UIImageView *)cycleBgImageView
{
    if(!_cycleBgImageView)
    {
        UIView *superView = self;
        _cycleBgImageView = [[UIImageView alloc]init];
        [superView addSubview:_cycleBgImageView];
        _cycleBgImageView.image = [UIImage imageNamed:@"battery_bg"];
    }
    return _cycleBgImageView;
}

- (TBCycleView *)cycleView
{
    if(!_cycleView)
    {
        UIView *superView = self;
        _cycleView = [[TBCycleView alloc]init];
        [superView addSubview:_cycleView];
    }
    return _cycleView;
}

- (UILabel *)batteryLabel
{
    if(!_batteryLabel)
    {
        UIView *superView = self;
        _batteryLabel = [[UILabel alloc]init];
        [superView addSubview:_batteryLabel];
        [_batteryLabel setFont:[UIFont systemFontOfSize:60]];
        [_batteryLabel setTextColor:greenColor];
//        _batteryLabel.text = @"75%";
    }
    return _batteryLabel;
}
- (UILabel *)battery
{
    if(!_battery)
    {
        UIView *superView = self;
        _battery = [[UILabel alloc]init];
        [superView addSubview:_battery];
//        [_battery setFont:[UIFont systemFontOfSize:16]];
        [_battery setTextColor:greenColor];
        _battery.text = MyNSLocalizedString(@"剩余电量");
    }
    return _battery;
}

- (UILabel *)tipsTitleLabel
{
    if(!_tipsTitleLabel)
    {
        UIView *superView = self;
        _tipsTitleLabel = [[UILabel alloc]init];
        [superView addSubview:_tipsTitleLabel];
        [_tipsTitleLabel setFont:[UIFont boldSystemFontOfSize:13]];
        [_tipsTitleLabel setTextColor:greenColor];
        _tipsTitleLabel.text = MyNSLocalizedString(@"温馨提示:");
    }
    return _tipsTitleLabel;
}

- (UILabel *)tipsLabel
{
    if(!_tipsLabel)
    {
        UIView *superView = self;
        _tipsLabel = [[UILabel alloc]init];
        [superView addSubview:_tipsLabel];
        [_tipsLabel setFont:[UIFont systemFontOfSize:13]];
        _tipsLabel.numberOfLines = 0;
        [_tipsLabel setTextColor:greenColor];
        _tipsLabel.text = MyNSLocalizedString(@"您在APP界面可随时查看耳机的剩余电量，也可选择手机顶部状态栏界面实时查看电量情况。(部分机型不支持)");
    }
    return _tipsLabel;
}

- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    
    [self.cycleBgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(300));
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.width.height.mas_equalTo(px1920Height(800));
    }];
    
    [self.cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(superView.mas_top).with.offset(px1920Height(300));
        make.centerX.mas_equalTo(superView.mas_centerX);
        make.width.height.mas_equalTo(px1920Height(800));
    }];
    
    [self.batteryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(self.cycleView);
    }];
    
    [self.battery mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.batteryLabel.mas_centerX);
        make.top.mas_equalTo(self.batteryLabel.mas_bottom).with.offset(px1920Height(50));
    }];
    
    [self.tipsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.cycleView.mas_bottom).with.offset(px1920Height(70));
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(170));
        make.right.mas_equalTo(superView.mas_right).with.offset(px1080Width(-170));
    }];
    
    [self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.tipsTitleLabel.mas_bottom);
        make.left.mas_equalTo(superView.mas_left).with.offset(px1080Width(170));
        make.right.mas_equalTo(superView.mas_right).with.offset(px1080Width(-170));
    }];
    
}

@end
